$(function() {


    var tit_user = getCookie("user");
    if (tit_user) {
        $(".adad").hide();
        $(".hy").show().text(`${tit_user},欢迎你`);
        $(".hy").click(function() {
            if (confirm("确定退出登录吗?")) {
                setCookie("user", `${tit_user}`, day = -1, path = "/");
                $(".adad").show();
                $(".hy").hide();
            }
        })
    }


    //判断是否有cookie 并跳转购物车页面
    $(".shopCart a").click(function() {
        if (document.cookie) {
            location.href = "../html/shoppingCar.html";
        } else {
            alert("请先登录");
        }
    })
    var user = document.cookie.split("=")[1];
    $.ajax({
        type: "get",
        url: "../php/isMyLikeSel.php",
        data: {
            user
        },
        dataType: "json",
        success: function(result) {
            var { status, msg, list } = result;
            if (status) {
                var html = "";
                list.forEach(({ goodsImg, goodsName, goodsPrice, id }) => {
                    html += `<li data_id=${id} >
                    <img src="${goodsImg}" alt="">
                    <h2 class="s2">${goodsName}</h2>
                    <p><span>${goodsPrice}</span></p>
                    <a href="javascript:;" class="del">×</a>
                </li>`;
                });
                $(".content_list").append(html);


                $(".del").click(function() {
                    var user = document.cookie.split("=")[1];
                    var id = $(this).parents("li").attr("data_id");
                    $(this).parents("li").remove();
                    $.ajax({
                        type: "get",
                        url: "../php/isMyLikeSelDel.php",
                        data: {
                            user,
                            id
                        },
                        dataType: "json",
                        success: function(result) {
                            var { status, msg, list } = result;
                            console.log(result);
                            if (status) {

                            } else {
                                alert(msg);
                            }
                        }
                    })
                })

            } else {
                console.log(msg);
            }
        }
    })


})